<%@page import="org.yate.oa.model.LoginEntity"%>
<%@page import="java.text.SimpleDateFormat, java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set value="${pageContext.request.contextPath}" var="ctx" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>加班</title>
<link href="${ctx}/css/skin.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/jquery-ui-timepicker-addon.css" rel="stylesheet"
	type="text/css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery-ui-sliderAccess.js"></script>
<script type="text/javascript"
	src="${ctx}/js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="${ctx}/js/backOffice.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#beginDate").datetimepicker();
		$("#endDate").datetimepicker();
	});

	function checkForm() {
		$("#errRemark").html("");
		$("#errDate").html("");
		var remark = $.trim($("#remark").val());
		var beginDate = $.trim($("#beginDate").val());
		var endDate = $.trim($("#endDate").val());
		var isKF = $("#ckIsKF").attr("checked")=="checked";
		if (remark == "") {
			$("#errRemark").html("加班事由不能为空。");
			$("#remark").focus();
			return false;
		}
		if (beginDate == "" || endDate == "") {
			$("#errDate").html("加班日期不能为空。");
			return false;
		}
		beginDate = new Date(beginDate);
		endDate = new Date(endDate);
		var diff = parseFloat(
				(endDate.getTime() - beginDate.getTime()) / (3600 * 1000))
				.toFixed(2);//相减得出小时差
		if (beginDate.getHours() <= 11 && endDate.getHours() >= 13 && !isKF) {
			//减去中午午休时间
			diff = diff - 1.33;
		}
		if (diff <= 0) {
			$("#errDate").html("加班时长必须是大于0。");
			return false;
		}
		if (confirm("您本次加班时间是：" + beginDate.getFullYear() + "年"
				+ (beginDate.getMonth() + 1) + "月" + beginDate.getDate() + "日 "
				+ beginDate.getHours() + "时" + beginDate.getMinutes() + "分 至 "
				+ endDate.getFullYear() + "年" + (endDate.getMonth() + 1) + "月"
				+ endDate.getDate() + "日 " + endDate.getHours() + "时"
				+ endDate.getMinutes() + "分，合计：" + diff + "小时。是否确认并提交？")) {
			var obj = {};
			obj.type = 'add';
			obj.taskType = 'workovertime';
			obj.beginDate = beginDate.getTime();
			if (isKF) {
				obj.days = parseFloat(diff / 6).toFixed(2);
			} else {
				obj.days = parseFloat(diff / 7.5).toFixed(2);
			}
			obj.endDate = endDate.getTime();
			obj.isKF = isKF;
			obj.remark = remark;
			$.ajax({
				type : 'post',
				dataType : 'json',
				data : obj,
				url : '${ctx}/task/post',
				success : function(data) {
					if (data.code == 200) {
						window.location.href = "overtime-list.jsp";
					} else {
						$.msgbox.show({
							message : data.msg,
							icon : 'no'
						});
					}
				}
			});
		} else {
			return false;
		}
	}

	function reset() {
		$("#remark").val("");
		$("#beginDate").val("");
		$("#endDate").val("");
		$("#remark").focus();
	}
</script>
</head>
<body>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="17" height="29" valign="top"
				background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/left-top-right.gif" width="17" height="29" /></td>
			<td width="" height="29" valign="top"
				background="${ctx}/images/content-bg.gif"><table width="100%"
					height="31" border="0" cellpadding="0" cellspacing="0"
					class="left_topbg" id="table2">
					<tr>
						<td height="31"><div class="titlebt">申请加班</div></td>
					</tr>
				</table></td>
			<td width="16" valign="top"
				background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/nav-right-bg.gif" width="16" height="29" /></td>
		</tr>
		<tr>
			<td height="71" valign="middle"
				background="${ctx}/images/mail_leftbg.gif">&nbsp;</td>
			<td valign="top" bgcolor="#F7F8F9"><table width="100%"
					height="138" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td height="13" valign="top">&nbsp;</td>
					</tr>
					<tr>
						<td valign="top"><table width="98%" border="0" align="center"
								cellpadding="0" cellspacing="0">
								<tr>
									<td class="left_txt">当前位置：申请加班</td>
								</tr>
								<tr>
									<td height="20"><table width="100%" height="1" border="0"
											cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
											<tr>
												<td></td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td><table width="100%" height="55" border="0"
											cellpadding="0" cellspacing="0">
											<tr>
												<td width="10%" height="55" valign="middle"><img
													src="${ctx}/images/title.gif" width="54" height="55"></td>
												<td width="90%" valign="top"><span class="left_txt2">
														加班说明：<br>
														本表必须在加班之前填报、审批,事后补填申请一律不予批准;特殊情况无法提前填报者,必须于加班后的第1个工作日填报、审批，经领导审批后交人力资源及行政管理中心备案。
												</span></td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td><table width="100%" height="31" border="0"
											cellpadding="0" cellspacing="0" class="nowtable">
											<tr>
												<td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;加班单填写</td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td width="100%" valign="top"
										style="min-height: 350px; height: 350px;">
										<%
											LoginEntity user = (LoginEntity) session.getAttribute("user");
										%>
										<table class="tblBill" cellpadding="0" cellspacing="0">
											<tr>
												<td>填报时间：</td>
												<td><%=new SimpleDateFormat("yyyy年MM月dd日").format(new Date())%></td>
											</tr>
											<tr>
												<td>姓名：</td>
												<td><input type="text" name="name" id="name"
													readonly="readonly" value="<%=user.getUsername()%>" /></td>
											</tr>
											<tr>
												<td>加班事由：</td>
												<td><textarea rows="5" cols="100" name="remark"
														id="remark"></textarea><span class="spanError"
													id="errRemark"></span></td>
											</tr>
											<tr>
												<td>加班日期：</td>
												<td><input type="text" id="beginDate"
													style="width: 230px;" /> 至 <input type="text" id="endDate"
													style="width: 230px;" /> <span class="spanError"
													id="errDate"></span></td>
											</tr>
											<tr>
												<td>客服每天按6小时计算：</td>
												<td><input id="ckIsKF" type="checkbox" title="非客服人员可以忽视此选项" /></td>
											</tr>
											<tr>
												<td></td>
												<td><input type="button" value=" 提交申请 "
													onclick="checkForm()" /> <input type="button" value=" 清空 "
													onclick="reset()" /></td>
											</tr>
										</table>
									</td>
								</tr>
							</table></td>
					</tr>
				</table></td>
			<td background="${ctx}/images/mail_rightbg.gif">&nbsp;</td>
		</tr>
		<tr>
			<td valign="middle" background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/buttom_left2.gif" width="17" height="17" /></td>
			<td height="17" valign="top"
				background="${ctx}/images/buttom_bgs.gif"><img
				src="${ctx}/images/buttom_bgs.gif" width="17" height="17" /></td>
			<td background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/buttom_right2.gif" width="16" height="17" /></td>
		</tr>
	</table>
</body>
</html>